package com.honeywell.iotserver.repository;

import java.math.BigInteger;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class DevicesDynamicQueryRepository {
	

	@Autowired
    @PersistenceContext
	private  EntityManager entityManager;  
	
	@SuppressWarnings("unchecked")
	
	public List<Object> findDeviceLists(String sqlCondition){
		return entityManager.createNativeQuery(sqlCondition).getResultList();
	}
	
	
	/**
	 * @param sqlCondition
	 * @return  int
	 * 查询摄像头总数
	 */
	public int  deviceCount(String sqlCondition){
		return ((BigInteger) entityManager.createNativeQuery(sqlCondition).getSingleResult()).intValue();
	}
}
